package com.ruoyi.web.controller.wlwsys.jintao;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.WlwsysDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

/**
 * @program: RuoYi-Vue-master
 * @Date: 2023-07-19 17:35
 * @author: jintao
 * @description: TODO
 */

@RestController
@RequestMapping("/device")
public class WlwDeviceController extends BaseController {
    @Autowired
    private WlwsysDeviceService wlwsysDeviceService;

    //条件分页查询
    @PostMapping("/getListByDevicePage")
    public TableDataInfo getListByDevicePage(@RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize,
    @RequestParam(value = "deviceId",required = false)String deviceId, @RequestParam(value = "deviceName",required = false)String deviceName,
    @RequestParam(value = "projectId",required = false)String projectId,@RequestParam(value = "startTime",required = false)String startTime,
    @RequestParam(value = "endTime",required = false)String endTime) throws ParseException {
        return getDataTable(wlwsysDeviceService.getDeviceByPageInfo(pageNum,pageSize,deviceId,deviceName,projectId,startTime,endTime));
    }

    //逻辑删除数据
    @PostMapping("/deleteDeviceById")
    public void deleteDeviceById(@RequestParam("deviceId")String deviceId){
        wlwsysDeviceService.deleteByDeviceId(deviceId);
    }

    //添加设备
    @PostMapping("/addDevice")
    public void addDevice( @RequestParam(value = "deviceName",required = false)String deviceName,
    @RequestParam(value = "deviceIntroduce",required = false)String  deviceIntroduce,@RequestParam(value = "projectId",required = false)String projectId) throws ParseException {
        wlwsysDeviceService.insertDevice(deviceName,deviceIntroduce,projectId);
    }

    //更新设备
    @PostMapping("/updateDevice")
    public boolean updateDevice(@RequestParam(value = "deviceId",required = false)String deviceId, @RequestParam(value = "deviceName",required = false)String deviceName,
    @RequestParam(value = "deviceIntroduce",required = false)String  deviceIntroduce,@RequestParam(value = "projectId",required = false)String projectId) throws ParseException {
        return wlwsysDeviceService.UpdateDevice(deviceId,deviceName,deviceIntroduce,projectId);
    }

    //获取新增的下拉列表
    @PostMapping("/getDropdownForAddDevice")
    public List<String> getDropdownForAddDevice() throws ParseException {
        return wlwsysDeviceService.selectDropdownForAddDevice(getUserId());
    }

    //获取修改的下拉列表
    @PostMapping("/getDropdownForUpdateDevice")
    public List<String> getDropdownForUpdateDevice(String projectId) throws ParseException {
        return wlwsysDeviceService.selectDropdownForUpdateDevice(projectId);
    }
}

